<?php
/**
 *	[贴内楼主N格（新帖、热贴、自定义）(topic_on_ceil.{modulename})] (C)2013-2099 Powered by wenqibo.
 *	Version: 1.0
 *	Date: 2013-2-2 20:48
 */

if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}
class plugin_topic_on_ceil{

}
class plugin_topic_on_ceil_forum extends plugin_topic_on_ceil {
	function viewthread_useraction() {
		global  $_G;
		$topic = $_G['cache']['plugin']['topic_on_ceil'];
		$allow_fids = implode(",", dunserialize($topic['allow_fids']));
		$topic_arry = array(1, 2);
		$left_topic_type = $this->adjust_topic_type($topic['left_topic'], $topic_arry);
		$left_topic_name = $this->get_topic_name($left_topic_type);
		$left_topic_content = $this->search($left_topic_type, $allow_fids);

		$right_topic_type = $this->adjust_topic_type($topic['right_topic'], $topic_arry);
		$right_topic_name = $this->get_topic_name($right_topic_type);
		$right_topic_content = $this->search($right_topic_type, $allow_fids);

		include template('topic_on_ceil:content');
		return $return;
	}

	function search($topic_type, $allow_fids) {
		if($topic_type == 1){
			$sql = "SELECT t.*, f.name FROM ".DB::table('forum_thread')." t, ".DB::table('forum_forum')." f WHERE f.status<>'3' AND f.fid=t.fid AND ".(empty($allow_fids) ? "" : "t.fid IN(".$allow_fids.") AND")." t.displayorder >= 0 ORDER BY t.dateline DESC LIMIT 0, 5";
		}else if($topic_type == 2){
			$sql = "SELECT t.*, f.name FROM ".DB::table('forum_thread')." t, ".DB::table('forum_forum')." f WHERE f.status<>'3' AND f.fid=t.fid AND ".(empty($allow_fids) ? "" : "t.fid IN(".$allow_fids.") AND")."  t.closed NOT LIKE 'moved|%' AND t.replies != 0 AND t.displayorder >= 0 ORDER BY t.lastpost DESC LIMIT 0, 5";
		}
		$objarray = array();
		$query = DB::query($sql);
		while($result = DB::fetch($query)) {
			$result['view_subject'] = cutstr($result['subject'], 50, '');
			$objarray[] = $result;
		}
		unset($sql, $query, $result);
		return $objarray;
	}

	function adjust_topic_type($topic_type, $topic_arry){
		if(!in_array($topic_type, $topic_arry)){
			return 1;
		}else{
			return $topic_type;
		}
	}
	function get_topic_name($topic_type){
		if($topic_type == 1){
			return lang('plugin/topic_on_ceil', 'last_post');
		}else if($topic_type == 2){
			return lang('plugin/topic_on_ceil', 'last_rep');
		}
	}
}

?>